import formatter from '@/common/formatter';

const base = { title: '电视沉默预计转活跃客户数量' }
const dataset = {
  source: [
    ['日期', '2023年返乡人数', '2024年返乡人数', '2024年返乡人数占比'],
    ['茂南', 186, 100, 0.32]
  ]
};

const seriesTemplate = [[
  // 'bar',
   'bar'], ['line']];

function getChartData([dataPool1, dataPool2], condition) {
  const collection = dataPool2['dianshihuoyueshu'];

  const sheetHeader = [['地区',
    //  '2023年返乡人数',
    'IPTV沉默预计转活跃用户数', 'IPTV沉默预计转活跃用户占比',]]

  const data = sheetHeader.concat(
    collection.map((row) => {
      const { region, fanxiangrenshu2023, fanxiangrenshu2024, fanxiangrenshuzhanbi2024 } = row;
      return [region,
        // fanxiangrenshu2023,
        fanxiangrenshu2024, fanxiangrenshuzhanbi2024,]
    })
  )
  this.dataset.source = data;
  return data;
}

// ======更新内容↑========

const series = seriesTemplate.flatMap((arr, index) =>
  arr.map(type => ({ type, yAxisIndex: index }))
);

const source = dataset.source;

export default {
  title: {
    text: base.title,
    left: 'center'
  },
  legend: {
    type: 'scroll',
    top: 30
  },
  tooltip: {
    trigger: window.isMobile ? 'item' : 'axis',
    axisPointer: {
      type: 'cross',
      crossStyle: {
        color: '#999'
      }
    },
    formatter: (params) => {
      if (window.isMobile) {
        const value = params.value[params.dimensionNames.indexOf(params.seriesName)];
        let tip = `<div class="space-y-1 px-2"><div class='font-bold'>${params.name}</div>`;
        tip += `<div class='flex justify-between space-x-6 p-0'>
        <span>${params.marker + params.seriesName}</span>
        <span class="font-bold">${value ? formatter.valueToText(value, params.seriesName.includes('占比')) : '-'}</span>
        </div>`
        tip += '</div>'
        return tip
      } else {
        let tip = `<div class="space-y-1 px-2"><div class='font-bold'>${params[0].name}</div>`;
        params.forEach((item, index) => {
          const value = item.value[item.dimensionNames.indexOf(item.seriesName)];
          tip += `<div class='flex justify-between space-x-6 p-0'>
        <span>${item.marker + item.seriesName}</span>
        <span class="font-bold">${
					value
						? index === 1
							? formatter.valueToText(value, true, 2)
							: value
						: '-'
				}</span >
        </div>`;
        });
        tip += '</div>'
        return tip
      }
    }
  },
  grid: {
    width: '96%',
    height: '80%',
    left: '2%',
    right: '2%',
    top: '16%',
    bottom: '2%',
    containLabel: true
  },
  dataset,
  xAxis: {
    type: 'category',
    axisPointer: {
      type: 'shadow'
    }
  },
  yAxis: [
    {
      type: 'value',
      name: ''
    }, {
      type: 'value',
      name: '',
      axisLabel: {
        formatter: (value) => formatter.valueToText(value, true)
      },
      axisPointer: {
        label: {
          formatter: (params) => formatter.valueToText(params.value, true)
        }
      }
    }
  ],
  series,
  getChartData,
}